/**
 * Created by reeveslee on 16/6/30.
 */
function fileSelected() {

    // 获取需要上传的文件
    var oFile = document.getElementById('image_file').files[0];

    // 验证文件格式
    var rFilter = /^(image\/bmp|image\/gif|image\/jpeg|image\/png|image\/tiff)$/i;
    if (!rFilter.test(oFile.type)) {
        //document.getElementById('error').style.display = 'block';
        return;
    }

    // 检测文件大小 - 不大于1M
    if (oFile.size > 1048576) {
        //document.getElementById('warnsize').style.display = 'block';
        return;
    }

    // 预览窗口
    var oImage = document.getElementById('preview');

    // prepare HTML5 FileReader
    var oReader = new FileReader();
    oReader.onload = function (e) {

        // e.target.result contains the DataURL which we will use as a source of the image
        oImage.src = e.target.result;
        document.getElementById('picView').style.display = 'block';
        document.getElementById('addPic').style.display = 'none';

        oImage.onload = function () { // binding onload event

            // we are going to display some custom image information here
            sResultFileSize = bytesToSize(oFile.size);
        };
    };

    // read selected file as DataURL
    oReader.readAsDataURL(oFile);
}